Public Class frmSUBSCRIPTION
    Private Sub Reload()
        If txtCustomerCode.Text <> "" Then
            Dim dt As DataTable
            Dim arName As New ArrayList
            arName.Add("@cus_code")
            Dim arVal As New ArrayList
            arVal.Add(txtCustomerCode.Text)

            dt = BLL.ObjectGetBy("SUBSCRIPTION_LOAD", arName, arVal)
            GridOrder.DataSource = dt
            dt = BLL.ObjectGetBy("SUBSCRIPTION_GETOUT_LOAD", arName, arVal)
            GridGetOut.DataSource = dt
            dt = BLL.ObjectGetBy("SUBSCRIPTION_LOADPAYMENT", arName, arVal)
            GridPayment.DataSource = dt
        End If
    End Sub

    Private Sub frmSUBSCRIPTION_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Try
            GC.Collect()
            Me.Dispose()
        Catch ex As Exception

        End Try
    End Sub
    Private Sub frmSUBSCRIPTION_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        PublicFunction.NewFormLoad(Me)
        Me.GridOrder.RootTable.Columns("TOTAL_ORG").FormatString = PublicVariable.NumberFormatString
        Me.GridOrder.RootTable.Columns("TOTAL_ORG").TotalFormatString = PublicVariable.NumberFormatString
        Me.GridOrder.RootTable.Columns("QUANTITY").FormatString = PublicVariable.NumberFormatString
        Me.GridOrder.RootTable.Columns("QUANTITY").TotalFormatString = PublicVariable.NumberFormatString
        Me.GridOrder.RootTable.Columns("LINE_TOTAL").FormatString = PublicVariable.NumberFormatString
        Me.GridOrder.RootTable.Columns("LINE_TOTAL").TotalFormatString = PublicVariable.NumberFormatString
        Me.GridOrder.RootTable.Columns("GETOUT").FormatString = PublicVariable.NumberFormatString
        Me.GridOrder.RootTable.Columns("GETOUT").TotalFormatString = PublicVariable.NumberFormatString
        Me.GridOrder.RootTable.Columns("REMAIN").FormatString = PublicVariable.NumberFormatString
        Me.GridOrder.RootTable.Columns("REMAIN").TotalFormatString = PublicVariable.NumberFormatString
        Me.GridOrder.RootTable.Columns("DSC_AMT").FormatString = PublicVariable.NumberFormatString
        Me.GridOrder.RootTable.Columns("DSC_AMT").TotalFormatString = PublicVariable.NumberFormatString
        Me.GridOrder.RootTable.Columns("VAT_AMT").FormatString = PublicVariable.NumberFormatString
        Me.GridOrder.RootTable.Columns("VAT_AMT").TotalFormatString = PublicVariable.NumberFormatString

        Me.GridGetOut.RootTable.Columns("QUANTITY").FormatString = PublicVariable.NumberFormatString
        Me.GridGetOut.RootTable.Columns("QUANTITY").TotalFormatString = PublicVariable.NumberFormatString
        Me.GridGetOut.RootTable.Columns("GET_DATE").FormatString = PublicVariable.DateTimeFormat

        Me.GridPayment.RootTable.Columns("PAY_AMT").FormatString = PublicVariable.NumberFormatString
        Me.GridPayment.RootTable.Columns("PAY_DATE").FormatString = PublicVariable.DateTimeFormat
        Me.GridPayment.RootTable.Columns("PAY_AMT").TotalFormatString = PublicVariable.NumberFormatString
        Reload()
    End Sub

    Private Sub btnGetOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetOut.Click
        If GridOrder.CurrentRow Is Nothing Then Return
        Dim frm As New frmNUMBER
        If frm.ShowDialog = Windows.Forms.DialogResult.OK Then
            If IsNumeric(frm.txtNumber.Text) Then
                'Update GetOut
                Dim Qty As Double = CDbl(frm.txtNumber.Text)
                Dim dt As DataTable
                Dim arName As New ArrayList
                arName.Add("@ITEM_CODE")
                arName.Add("@ITEM_NAME")
                arName.Add("@QUANTITY")
                arName.Add("@BILL_CODE")
                Dim arVal As New ArrayList
                arVal.Add(GridOrder.GetValue("ITEM_CODE").ToString)
                arVal.Add(GridOrder.GetValue("ITEM_NAME").ToString)
                arVal.Add(Qty)
                arVal.Add(GridOrder.GetValue("BILL_CODE"))
                dt = BLL.ObjectGetBy("SUBSCRIPTION_ADD", arName, arVal)
                If dt.Rows.Count > 0 Then
                    'BLL.ReturnXML("SUBSCRIPTION", dt)
                    Reload()
                End If
            End If
        End If
    End Sub

    Private Sub btnNewSubscription_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewSubscription.Click
        Dim frm As New frmORDER
        frm.TBL_CODE = ""
        frm.TBL_NAME = ""
        frm.txtCustomer.Text = Me.txtCustomerName.Text
        frm.txtTBL_NAME.Text = ""
        frm.CustomerCode = Me.txtCustomerCode.Text
        frm.ShowDialog()
        If frm.BillCode > 0 Then
            Dim dt As DataTable
            Dim arName As New ArrayList
            arName.Add("@BILL_CODE")
            Dim arVal As New ArrayList
            arVal.Add(frm.BillCode)
            dt = BLL.ObjectGetBy("BILL_SUBSCRIPTION", arName, arVal)
            If dt.Rows.Count > 0 Then
                'BLL.ReturnXML("SUBSCRIPTION", dt)
                Reload()
            End If
        End If
    End Sub

    Private Sub btnPayment_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPayment.Click
        Dim frm As New frmSETTLE
        frm.BillCode = GridOrder.GetValue("BILL_CODE")
        frm.Total = GridOrder.GetValue("LINE_TOTAL")
        frm.SVCAmt = 0
        frm.SubTotal = GridOrder.GetValue("TOTAL_ORG")
        frm.DiscountAmt = GridOrder.GetValue("DSC_AMT")
        frm.TaxAmt = GridOrder.GetValue("VAT_AMT")
        frm.CustomerCode = txtCustomerCode.Text
        frm.TipAmt = 0
        If frm.ShowDialog() = Windows.Forms.DialogResult.OK Then
            If frm.BillCode > 0 Then
                Dim dt As DataTable
                Dim arName As New ArrayList
                arName.Add("@BILL_CODE")
                Dim arVal As New ArrayList
                arVal.Add(frm.BillCode)
                dt = BLL.ObjectGetBy("BILL_SUBSCRIPTION", arName, arVal)
                If dt.Rows.Count > 0 Then
                    'BLL.ReturnXML("SUBSCRIPTION", dt)
                    Reload()
                End If
            End If
        End If
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub
End Class